package com.leyou.page.web;

import com.leyou.page.service.GoodsPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("page")
public class PageController {
    //返回值都String的原因是 数据都要存储到OpenResty中的context及(动态展示的数据)

    @Autowired
    private GoodsPageService goodsPageService;


    /**
     * 查询商品spu数据
     * @param spuId 商品id
     * @return spu数据
     */
    @GetMapping("/spu/{id}")
    public ResponseEntity<String> querySpuBySpuID(@PathVariable("id") Long spuId){
        return ResponseEntity.ok(goodsPageService.querySpuBySpuID(spuId));
    }

        /**
         * 查询商品sku数据
         * @param spuId 商品id
         * @return sku数据
         */
        @GetMapping("/sku/{id}")
        public ResponseEntity<String> querySkuListBySpuID(@PathVariable("id") Long spuId){
            return ResponseEntity.ok(goodsPageService.querySkuListBySpuID(spuId));
        }

        /**
         * 查询商品spuDetail数据
         * @param spuId 商品id
         * @return spu数据
         */
        @GetMapping("/detail/{id}")
        public ResponseEntity<String> querySpuDetailBySpuID(@PathVariable("id") Long spuId){
            return ResponseEntity.ok(goodsPageService.querySpuDetailBySpuID(spuId));
        }

        /**
         * 查询商品分类数据
         * @param ids 商品分类id
         * @return 分类数据
         */
        @GetMapping("/categories")
        public ResponseEntity<String> queryCategoriesByIds(@RequestParam("ids") List<Long> ids){
            return ResponseEntity.ok(goodsPageService.queryCategoriesByIds(ids));
        }

        /**
         * 根据brand_id查询品牌
         * @param id 品牌id
         * @return
         */
        @GetMapping("/brand/{id}")
        public ResponseEntity<String> queryBrandById(@PathVariable("id") Long id){
            return ResponseEntity.ok(goodsPageService.queryBrandById(id));
        }

        /**
         * 查询规格数据
         * @param categoryId 分类id
         * @return 规格参数
         */
        @GetMapping("/spec/{id}")
        public ResponseEntity<String> querySpecGroupListById(@PathVariable("id") Long categoryId){
            return ResponseEntity.ok(goodsPageService.querySpecGroupListById(categoryId));
        }

}
